package model;

import java.util.Objects;

class Course {
    private String courseId;        // 课程号
    private String courseName;      // 课程名
    private int credit;             // 学分
    private Teacher teacher;        // 授课老师（包含性别信息）
    private String timeAndLocation; // 时间地点

    public Course(String courseId, String courseName, int credit,
                  Teacher teacher, String timeAndLocation) {
        this.courseId = courseId;
        this.courseName = courseName;
        this.credit = credit;
        this.teacher = teacher;
        this.timeAndLocation = timeAndLocation;
    }

    // getter方法
    public String getCourseId() {
        return courseId;
    }

    public String getCourseName() {
        return courseName;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    // 重写equals和hashCode确保课程唯一性（基于课程号）
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Course course = (Course) o;
        return Objects.equals(courseId, course.courseId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(courseId);
    }

    // 课程信息字符串（含老师姓名和性别）
    @Override
    public String toString() {
        return String.format(
                "课程号: %s | 课程名: %s | 学分: %d | 时间地点: %s",
                courseId, courseName, credit, timeAndLocation
        );
    }
}
